var followId = JSON.parse(sessionStorage.getItem("followId"));
var type = JSON.parse(sessionStorage.getItem("type"));
var index = 0;

// 视频URL
var videoUrl = "";

$(function () {
    if (type == "jcyk") {
        getResource();
    } else if (type == "fourBook_shiPinSuCai") {
        getFourBookShiPinSuCai();
    } else if (type == "fourBook_jingCaiYiKe") {
        getFourBookJingCaiYiKe();
    } else if (type == "mingShi_woDeShiPin") {
        getMingShiWoDeShiPin();
    } else if (type == "ggzyk_zheJiangShiPin") {
        getGgzykZheJiangShiPin();
    } else if (type == "zjjs_zheJiangShiPin") {
        getGgzykZheJiangShiPin();
    } else if (type == "shouYe_jingCaiYiKe") {
        getResource();
    }

    $("#downloadBtn").click(function () {
        var downloadForm = $("<form method='get'></form>");

        downloadForm.attr("action", videoUrl);

        $(document.body).append(downloadForm);

        //提交表单，实现下载
        downloadForm.submit();
    });
})

// 精彩一课
function getResource() {
    var data = {
        id: parseInt(followId)
    };

    AjaxSubmit("GET", data, basePath + "/common/resource/getCommonResourceById", getResource_fun);
}
function getResource_fun(res) {
    type = "jcyk";
    var videoLists = res.obj;
    console.log(res);
    if (res.status == "SUCCESS") {
        videoUrl = videoLists.fileUrl;
        $(".videobox").find("h3").html(videoLists.title);
        $(".videobox").find("p").append('<span>来源：</span><span>' + videoLists.whereFrom + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>时间：</span><span>' + changeTime(videoLists.creatTime) + '</span>');
        $("#videoSource").append('<video style="width: 600px;height: 400px" controls="" autoplay="" name="media"><source src="' + videoLists.fileUrl + '"></video>');
    }
}

// 视频素材
function getFourBookShiPinSuCai() {
    var data = {
        id: parseInt(followId)
    };

    AjaxSubmit("GET", data, basePath + "/common/resource/getCommonResourceById", getFourBookShiPinSuCaiRes);
}
function getFourBookShiPinSuCaiRes(res) {
    type = "fourBook_shiPinSuCai";
    var videoLists = res.obj;
    console.log(res);
    if (res.status == "SUCCESS") {
        videoUrl = videoLists.fileUrl;
        $(".videobox").find("h3").html(videoLists.title);
        $(".videobox").find("p").append('<span>来源：</span><span>' + videoLists.whereFrom + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>时间：</span><span>' + changeTime(videoLists.creatTime) + '</span>');
        $("#videoSource").append('<video style="width: 600px;height: 400px" controls="" autoplay="" name="media"><source src="' + videoLists.fileUrl + '"></video>');
    }
}

// 四本书-->精彩一课
function getFourBookJingCaiYiKe() {
    var data = {
        id: parseInt(followId)
    };

    AjaxSubmit("GET", data, basePath + "/common/resource/getCommonResourceById", getFourBookJingCaiYiKeRes);
}
function getFourBookJingCaiYiKeRes(res) {
    type = "fourBook_shiPinSuCai";
    var videoLists = res.obj;
    console.log(res);
    if (res.status == "SUCCESS") {
        videoUrl = videoLists.fileUrl;
        $(".videobox").find("h3").html(videoLists.title);
        $(".videobox").find("p").append('<span>来源：</span><span>' + videoLists.whereFrom + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>时间：</span><span>' + changeTime(videoLists.creatTime) + '</span>');
        $("#videoSource").append('<video style="width: 600px;height: 400px" controls="" autoplay="" name="media"><source src="' + videoLists.fileUrl + '"></video>');
    }
}

// 我的视频
function getMingShiWoDeShiPin() {
    var data = {
        id: parseInt(followId)
    };

    AjaxSubmit("GET", data, basePath + "/common/resource/getResourceById", getMingShiWoDeShiPinRes);
}
function getMingShiWoDeShiPinRes(res) {
    type = "";
    var videoLists = res.obj;
    // console.log(res);
    if (res.status == "SUCCESS") {
        videoUrl = videoLists.fileUrl;
        $(".videobox").find("h3").html(videoLists.title);
        $(".videobox").find("p").append('<span>来源：</span><span>' + videoLists.whereFrom + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>时间：</span><span>' + changeTime(videoLists.creatTime) + '</span>');
        $("#videoSource").append('<video style="width: 600px;height: 400px" controls="" autoplay="" name="media"><source src="' + videoLists.url + '"></video>');
    }
}

// 浙江视频
function getGgzykZheJiangShiPin() {
    var data = {
        id: parseInt(followId)
    };

    AjaxSubmit("GET", data, baseUrl + "/common/resource/searchCommonResource", getGgzykZheJiangShiPinRes);
}
function getGgzykZheJiangShiPinRes(res) {
    type = "ggzyk_zheJiangShiPin";
    var videoLists = res.obj.content[0];
    console.log(res);
    if (res.status == "SUCCESS") {
        videoUrl = videoLists.fileUrl;
        $(".videobox").find("h3").html(videoLists.title);
        $(".videobox").find("p").append('<span>来源：</span><span>' + videoLists.whereFrom + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>时间：</span><span>' + changeTime(videoLists.creatTime) + '</span>');
        $("#videoSource").append('<video style="width: 600px;height: 400px" controls="" autoplay="" name="media"><source src="' + videoLists.fileUrl + '"></video>');
    }
}